package com.baseproject.datasource.get.request.type;

import com.baseproject.datasource.get.procedure.DataProcedure;
import com.baseproject.datasource.get.response.BaseResponseHandler;

import java.util.ArrayList;
import java.util.List;

import static com.baseproject.json.JsonUtils.createJSONObject;

/**
 * Created by hp on 2017/8/18.
 */

public class JsonArrayRequestType extends ObjectRequestType {

    @Override
    public <T> List<T> getListFromRemoteResponseData(Object objectData, Class<T> className) {
        jsonArrayData = BaseResponseHandler.createResponseHandler(objectData).getJSONArrayData();
        if (null != jsonArrayData) {
            List<T> contentList = new ArrayList<T>() {{ add((T) jsonArrayData);}};
            return contentList;
        }
        return null;
    }

    @Override
    public <T> void save(List<T> contentList, DataProcedure dataProcedure) {
        jsonObjectData = createJSONObject(jsonArrayData);
        super.save(contentList, dataProcedure);
    }
}
